package com.openbravo.pos.reports;

import com.openbravo.basic.BasicException;
import com.openbravo.data.loader.Datas;
import com.openbravo.data.loader.QBFCompareEnum;
import com.openbravo.data.loader.SerializerWrite;
import com.openbravo.data.loader.SerializerWriteBasic;
import com.openbravo.pos.customers.CustomerInfo;
import com.openbravo.pos.customers.DataLogicCustomers;
import com.openbravo.pos.customers.JCustomerFinder;
import com.openbravo.pos.forms.AppLocal;
import com.openbravo.pos.forms.AppView;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.Document;

public class JParamsCustomer extends JPanel
  implements ReportEditorCreator
{
  private DataLogicCustomers dlCustomers;
  private CustomerInfo currentcustomer;
  private JButton btnCustomer;
  private JLabel jLabel1;
  private JTextField jTextField1;

  public JParamsCustomer()
  {
    initComponents();
    this.jTextField1.getDocument().addDocumentListener(new DocumentListener()
    {
    	public void insertUpdate(DocumentEvent documentevent) {
			currentcustomer = null;
		}

		public void removeUpdate(DocumentEvent documentevent) {
			currentcustomer = null;
		}

		public void changedUpdate(DocumentEvent documentevent) {
			currentcustomer = null;
		}

    });
  }

  public void init(AppView paramAppView)
  {
    this.dlCustomers = ((DataLogicCustomers)paramAppView.getBean("com.openbravo.pos.customers.DataLogicCustomers"));
  }

  public void activate()
    throws BasicException
  {
    this.currentcustomer = null;
    this.jTextField1.setText(null);
  }

  public SerializerWrite getSerializerWrite()
  {
    return new SerializerWriteBasic(new Datas[] { Datas.OBJECT, Datas.STRING, Datas.OBJECT, Datas.STRING });
  }

  public Component getComponent()
  {
    return this;
  }

  public Object createValue()
    throws BasicException
  {
    if (this.currentcustomer == null)
    {
      if ((this.jTextField1.getText() == null) || (this.jTextField1.getText().equals("")))
        return new Object[] { QBFCompareEnum.COMP_NONE, null, QBFCompareEnum.COMP_NONE, null };
      return new Object[] { QBFCompareEnum.COMP_NONE, null, QBFCompareEnum.COMP_RE, this.jTextField1.getText() };
    }
    return new Object[] { QBFCompareEnum.COMP_EQUALS, this.currentcustomer.getId(), QBFCompareEnum.COMP_NONE, null };
  }

  private void initComponents()
  {
    this.jLabel1 = new JLabel();
    this.jTextField1 = new JTextField();
    this.btnCustomer = new JButton();
    setBorder(BorderFactory.createTitledBorder(AppLocal.getIntString("label.bycustomer")));
    setPreferredSize(new Dimension(400, 60));
    setLayout(null);
    this.jLabel1.setText(AppLocal.getIntString("label.customer"));
    add(this.jLabel1);
    this.jLabel1.setBounds(20, 20, 120, 15);
    add(this.jTextField1);
    this.jTextField1.setBounds(140, 20, 200, 20);
    this.btnCustomer.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/kuser.png")));
    this.btnCustomer.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        JParamsCustomer.this.btnCustomerActionPerformed(paramActionEvent);
      }
    });
    add(this.btnCustomer);
    this.btnCustomer.setBounds(350, 20, 50, 26);
  }

  private void btnCustomerActionPerformed(ActionEvent paramActionEvent)
  {
    JCustomerFinder localJCustomerFinder = JCustomerFinder.getCustomerFinder(this, this.dlCustomers);
    localJCustomerFinder.search(this.currentcustomer);
    localJCustomerFinder.setVisible(true);
    this.currentcustomer = localJCustomerFinder.getSelectedCustomer();
    if (this.currentcustomer == null)
      this.jTextField1.setText(null);
    else
      this.jTextField1.setText(this.currentcustomer.getName());
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.pos.reports.JParamsCustomer
 * JD-Core Version:    0.6.0
 */